package com.lagou.test;

import com.lagou.entity.Emp;
import com.lagou.utils.JDBCUtils;

import java.sql.*;

public class JDBC_PrepareStatement {

    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = JDBCUtils.getConnection();
            String sql = "select * from employee where name =? and gender=?";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"zhangsan");
            ps.setString(2,"男");

            rs = ps.executeQuery();
            while(rs.next()){
                int id = rs.getInt("id");
                String name = rs.getString("name");
                String gender = rs.getString("gender");
                double salary = rs.getDouble("salary");
                double bonus = rs.getDouble("bonus");
                Date join_date = rs.getDate("join_date");

                Emp e = new Emp(id,name,gender,salary,bonus,join_date);
                System.out.println(e);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.close(conn,ps,rs);
        }

    }

}
